/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios';
// import { getToken, removeToken } from '../utils/auth';
// import Cookies from 'js-cookie';

enum ResultEnum {
    SUCCESS = 0,
    OVERDUE = '401',
    TIMEOUT = 1000000,
    TYPE = 'SUCCESS',
}

interface Result {
    code: number;
    msg: string;
    data?: any;
    success?: boolean;
}

const config = {
    baseURL: import.meta.env.VITE_APP_API_BASEURL,
    timeout: ResultEnum.TIMEOUT as number,
};

class RequestHttp {
    service: any;
    constructor(config: any) {
        // 实例化axios
        this.service = axios.create(config);

        this.service.interceptors.request.use(
            (config: any) => {
                // const Authorization: string | null = getToken()
                return {
                    ...config,
                    headers: {
                        Authorization:
                            'Bearer 59ab49783549a5bef80c0724925b7075d8e6956d812ea4ec1d14328b17c1485b-FOM-1.0.0',
                        Baggage:
                            'sentry-environment=production,sentry-public_key=93f22befcd114f7c94c8eceeb4a03b95,sentry-trace_id=3829829089984ee3af528c65db88f7e3',
                    },
                };
            },
            (error: any) => {
                return Promise.reject(error);
            }
        );
        this.service.interceptors.response.use(
            (response: any) => {
                const { data } = response;
                return data;
            },
            async (error: any) => {
                return Promise.reject(error);
            }
        );
    }

    get(url: string, params?: any, _object = {}): Promise<Result> {
        return this.service.get(url, { params, ..._object });
    }
    post(url: string, params?: object, _object = {}): Promise<Result> {
        return this.service.post(url, params, _object);
    }
    put(url: string, params?: object, _object = {}): Promise<Result> {
        return this.service.put(url, params, _object);
    }
    delete(url: string, params?: any, _object = {}): Promise<Result> {
        return this.service.delete(url, { params, ..._object });
    }
}

export default new RequestHttp(config);
